﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PerfAnalyzerLib;

namespace UnitTests
{
	class GeneratorCounterInfo
	{
		/// <summary>
		/// Generate long counter name. 
		/// </summary>
		/// <param name="withInstance">Create counter name with instance.</param>
		/// <returns></returns>
		public static string GenerateGenericCounterInfo(bool withInstance)
		{
			if (withInstance)
			{
				return GenerateCounterInfo("machine", "category", "instance", "name");
			}
			else
			{
				return GenerateCounterInfo("machine", "category", null, "name");
			}
		}

		public static string GenerateCounterInfo(int machineIndex, int categoryIndex, int instanceIndex, int nameIndex)
		{
			string machine = "machine" + machineIndex;
			string category = "category" + categoryIndex;
			string instance = "instance" + instanceIndex;
			string name = "name" + nameIndex;

			if (instanceIndex < 0)
			{
				return GenerateCounterInfo(machine, category, null, name);
			}

			return GenerateCounterInfo(machine, category, instance, name);
		}

		public static string GenerateCounterInfo(string machine, string category, string instance, string name)
		{
			if (string.IsNullOrWhiteSpace(instance))
			{
				return string.Format(@"\{0}\{1}\{2}", machine, category, name);
			}

			return string.Format(@"\{0}\{1}({2})\{3}", machine, category, instance, name);
		}
	}
}
